ConfigManagePortlet = Class.extend({
	init: function()	{
		this.name = "ConfigManagePortlet";
	},
	
	onBegin: function()	{
		this.registerObserver();
	},
	
	onEnd: function()	{
		this.unregisterObserver();
	},
	
	run: function()	{
		var obj = this;
		this.onAjax('config', 'get-config', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.model = {};
				obj.model.config = ret;
				obj.getPortletPlaceholder().paintCanvas(obj.render());
				var subject = SingletonFactory.getInstance(Subject);
				subject.notifyEvent('RenderTextEditor', {id: 'ConfigManagePortlet-About', content: ret.intro});
				subject.notifyEvent('RenderTextEditor', {id: 'ConfigManagePortlet-Contact', content: ret.contact});
				subject.notifyEvent('RenderTextEditor', {id: 'ConfigManagePortlet-AgentInfo', content: ret.agent_info});
				subject.notifyEvent('RenderTextEditor', {id: 'ConfigManagePortlet-Footer', content: ret.footer});
			}
		});
	},
	
	onConfigUpdateSubmit: function()	{
		//RETRIEVE TEXT EDITOR CONTENT
		var subject = SingletonFactory.getInstance(Subject);
		var obj = this;
		var intro = '';
		subject.notifyEvent('RetrieveTextEditorContent', {id: 'ConfigManagePortlet-About', callback: function(new_intro) {
			intro = new_intro;
		}});
		var contact = '';
		subject.notifyEvent('RetrieveTextEditorContent', {id: 'ConfigManagePortlet-Contact', callback: function(new_contact) {
			contact = new_contact;
		}});
		var agent_info = '';
		subject.notifyEvent('RetrieveTextEditorContent', {id: 'ConfigManagePortlet-AgentInfo', callback: function(new_agent_info) {
			agent_info = new_agent_info;
		}});
		var footer = '';
		subject.notifyEvent('RetrieveTextEditorContent', {id: 'ConfigManagePortlet-Footer', callback: function(new_footer) {
			footer = new_footer;
		}});
		obj.onAjax('admin', 'update-config', {intro: intro, contact: contact, agent_info: agent_info, footer: footer}, 'POST', {
				'onSuccess': function(ret)	{
					alert('Sửa cấu hình thành công');
				}
		});
	}
	
}).implement(PortletInterface).implement(RenderInterface).implement(AjaxInterface).implement(ObserverInterface);